//
//  XTCellOfbofang.m
//  TTLestening
//
//  Created by dllo on 16/3/26.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "XTCellOfbofang.h"
#import "CircularProgressView.h"
#import "XCModelForEveryone.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIColor+Wonderful.h"

#define WIDTH   [UIScreen mainScreen].bounds.size.width

@interface XTCellOfbofang ()


@end

@implementation XTCellOfbofang


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creaview];
        
        [[NSNotificationCenter defaultCenter] addObserverForName:@"nextSong" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
            
           // NSLog(@"%@", [note.userInfo objectForKey:@"index"]);
            NSArray *array = [note.userInfo objectForKey:@"array"];
            NSInteger index = [[note.userInfo objectForKey:@"index"] integerValue];
            //  NSInteger nexSong = ++index;
            // NSLog(@"%ld", nexSong);
            
            XCModelForEveryone *model = [array objectAtIndex:index];
            [self passModelForSong:model];
            
            
        }];

        
        
          }
    return self;
}

-(void)creaview{
    
    self.cirview = [[CircularProgressView alloc]init];
    self.cirview.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.cirview];
    
    self.cirview.backColor = [UIColor lightGrayColor];
    
    self.cirview.progressColor = [UIColor redColor];
   
    self.cirview.lineWidth = 2;
    
    
    self.backimage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.backimage];
    
    self.songname = [[UILabel alloc]init];
    [self.contentView addSubview:self.songname];
    
    self.songer = [[UILabel alloc]init];
    [self.contentView addSubview:self.songer];
  }

-(void)layoutSubviews{
    [super layoutSubviews];
    
   
    self.cirview.frame = CGRectMake(5, 2, 44, 44);
    
    self.backimage.frame = CGRectMake(0, 0, 40, 40);
    self.backimage.layer.cornerRadius = 20;
    self.backimage.layer.masksToBounds = YES;
   self.backimage.center = self.cirview.center;
    
    self.songname.frame = CGRectMake(55, 5, WIDTH - 165 , 25);
    self.songer.frame = CGRectMake(55, 30, WIDTH - 165, 15);
    
}

-(void)passModelForSong:(XCModelForEveryone *)model{


    self.songer.text = model.singerName;
    self.songname.text = model.name;
    [self.backimage sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
    
}


@end
